﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using Common;

public partial class Stock_InStock_Add : System.Web.UI.Page
{
    protected int InStockKey;

    protected string MenuType
    {
        get { return string.IsNullOrEmpty(Request["menutype"]) ? "" : Request["menutype"].ToString(); }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        InStockKey = string.IsNullOrEmpty(Request["InStockKey"]) ? 0 : Convert.ToInt32(Request["InStockKey"]);

        if (!this.IsPostBack)
        {

            if (InStockKey != 0)
            {
                Dat_InStock instock = new Dat_InStock();

                

                btnSubmit.Text = "修 改";
            }
       }
    }

    //添加
    protected void btnSubmit_Click(object sender, EventArgs e)
    {

        if (InStockKey == 0)
        {
            Dat_InStock instock = new Dat_InStock
            {
                InStockNO = new InStock().GetInStockNO(),
                StockKey = Convert.ToInt32(txt_StockKey.Value),
                Num = Convert.ToInt32(txt_Num.Text),
                CreateTime = DateTime.Now,
                UserKey = Convert.ToInt32(Session["UserKey"])
            };

            if (new InStock().AddInStock(instock))
            {
                WebUtility.JsAlertToGo("添加入库单成功", "Stock_Add.aspx?menutype=311");
            }
        }
        else
        {
            Dat_InStock instock = new Dat_InStock
            {
                InStockKey = InStockKey,
                Num = Convert.ToInt32(txt_Num.Text)
            };

            if (new InStock().EditInStock(instock))
            {
                WebUtility.JsAlertToGo("修改入库单成功", "InStock_Add.aspx?menutype=312");
            }
        }
    }

}
